import { currentDates, secondss } from '../../utils/util'
import { openPage } from '../../utils/map/open'
Page({
  data: {
    matter: '',
    // 评分
    rate: [],
    num: 3,
    touchStartTime: 0, // 触摸开始时间
    touchEndTime: 0, // 触摸结束时间
    lastTapTime: 0, // 最后一次单击事件点击发生时间
  },
  onLoad(options) {
    let { s_id } = options
    this._getDetail(s_id)
    this._getMatter(s_id)
    this._getExplanation(s_id)
    this.setData({
      s_id,
    })
  },
  // 打开导航
  openMap({ timeStamp }) {
    const {
      touchEndTime,
      touchStartTime,
      lastTapTime,
      p_name,
      c_name,
      a_name,
      address,
    } = this.data
    // 控制点击事件在350ms内触发，加这层判断是为了防止长按时会触发点击事件
    if (touchEndTime - touchStartTime < 350) {
      // 更新最后一次点击时间
      this.setData({
        lastTapTime: timeStamp,
      })
      // 如果两次点击时间在300毫秒内，则认为是双击事件
      if (timeStamp - lastTapTime > 300) {
        // do something 点击事件具体执行那个业务
        openPage({ p_name, c_name, a_name, address }, this)
      }
    }
  },
  // 获取详情
  async _getDetail(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/detail',
      data: {
        s_id,
      },
    })
    if (code == 0) {
      this.setData(data)
    }
  },
  // 获取评价列表
  async _getMatter(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/evaluate',
      data: {
        page: 1,
        s_id,
        type: 2,
      },
    })
    if (code == 0) {
      let rate = data.map((item) => {
        item.pics = item.pics.split(',')
        item.create_at =
          currentDates(item.create_at * 1000) + ' ' + secondss(item.create_at)
        return item
      })
      this.setData({
        rate,
      })
    }
  },
  // 获取亲子游戏说明
  async _getExplanation(s_id) {
    let { code, data } = await wx.requestAsync({
      url: '/shop/content',
      data: {
        page: 1,
        s_id,
        type: 2,
      },
    })
    if (code == 0) {
      console.log(data)

      this.setData({ content: data })
    }
  },
  // 评价列表
  _toLink() {
    const { s_id } = this.data
    let params = {
      type: 2,
      s_id,
    }
    wx.navigateTo({
      url:
        '/pages/evaluationlist/evaluationlist?params=' + JSON.stringify(params),
    })
  },
  // 提交
  submit() {
    const { s_id } = this.data
    wx.navigateTo({
      url: '/pages/pay/pay?s_id=' + s_id,
    })
  },
  _handleLeft(e) {
    console.log(e)
  },
  _handleRight() {},
  // 预约列表
  _toReservationList() {
    wx.navigateTo({
      url: '/pages/reservationList/reservationList',
    })
  },
})
